package com.dominator.controller.api;

import com.dominFramework.core.typewrap.Dto;
import com.dominFramework.core.utils.JsonUtils;
import com.dominator.enums.ReqEnums;
import com.dominator.service.ApiAccountService;
import com.dominator.service.ApiPointTicketService;
import com.dominator.utils.api.ApiMessage;
import com.dominator.utils.exception.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
@RequestMapping("/api/v1/ticket")
public class ApiTicketController {
    @Autowired
    HttpServletRequest request;

    @Autowired
    ApiPointTicketService apiPointTicketService;


    /**
     * 兑换码兑换积分
     *
     * @return
     */
    @RequestMapping("/exchange")
    @ResponseBody
    public ApiMessage exchange(@RequestParam String paramStr) {
        ApiMessage msg = new ApiMessage();
        try {
            Dto dto = JsonUtils.toDto(paramStr);
            msg = apiPointTicketService.exchange(dto);
        } catch (ApiException e) {
            msg.setCode(e.getCode());
            msg.setMessage(e.getMessage());
        } catch (Exception e) {
            log.error(e.getMessage());
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        } finally {
            return msg;
        }

    }




}
